﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace jqGrid.JeffSogolov.Models
{
    public class StaticDummyRepository : IDummyRepository
    {
        #region Fields
        private static List<DummyViewModel> _dummyViewModelList;
        #endregion

        #region Constructor
        static StaticDummyRepository()
        {
            _dummyViewModelList = new List<DummyViewModel>();
            for (int i = 0; i < 10; i++)
            {
                _dummyViewModelList.Add(new DummyViewModel()
                {
                    Id = i,
                    Updated = false,
                    FirstValue = "ValueA",
                    SecondValue = "ValueB",
                    Comparision = ""
                });
            }
            for (int i = 10; i < 20; i++)
            {
                _dummyViewModelList.Add(new DummyViewModel()
                {
                    Id = i,
                    Updated = false,
                    FirstValue = "ValueC",
                    SecondValue = "ValueD",
                    Comparision = ""
                });
            }
            for (int i = 20; i < 30; i++)
            {
                _dummyViewModelList.Add(new DummyViewModel()
                {
                    Id = i,
                    Updated = false,
                    FirstValue = "ValueE",
                    SecondValue = "ValueF",
                    Comparision = ""
                });
            }
        }
        #endregion

        public int GetCount()
        {
            return _dummyViewModelList.Where(d => !d.Updated).Count();
        }

        public DummyViewModel FindByKey(int key)
        {
            return _dummyViewModelList.FirstOrDefault(d => d.Id == key);
        }

        public IEnumerable<DummyViewModel> FindRange(string sortingExpression, int startIndex, int count)
        {
            return _dummyViewModelList.Where(d => !d.Updated).Skip(startIndex).Take(count);
        }
    }
}